package com.yunkaweilai.android.view.dialog.room;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import com.flyco.dialog.utils.CornerUtils;
import com.flyco.dialog.widget.base.BaseDialog;
import com.yunkaweilai.android.R;
import com.yunkaweilai.android.activity.operation.consumption.room.RoomInfoActivity;
import com.yunkaweilai.android.constants.Api;
import com.yunkaweilai.android.interfaces.SimpleInterface;
import com.yunkaweilai.android.net.HttpRequest;
import com.yunkaweilai.android.net.PostProcess;
import com.yunkaweilai.android.utils.Utils;

/**
 * 转台
 * Created by Administrator on 2016/12/22 0022.
 */

public class GuadanTurnRoomDialog extends BaseDialog<GuadanTurnRoomDialog> {
    TextView idTvRight;
    private Context context;
    private String gid;
    private TextView idTvClose;
    private String title;
    private String remark;
    private TextView idTvRoomName;
    private TextView idTvRemark;
    private String group_id;
    private SimpleInterface simpleInterface;
    public GuadanTurnRoomDialog(Context context, String gid, String title, String remark, String group_id, SimpleInterface simpleInterface) {
        super(context);
        this.group_id = group_id;
        this.context = context;
        this.gid = gid;
        this.title = title;
        this.remark = remark;
        this.simpleInterface = simpleInterface;
    }

    @Override
    public View onCreateView() {
        widthScale(0);
        //showAnim(new Swing());
        //dismissAnim(this, new ZoomOutExit());
        View inflate = View.inflate(mContext, R.layout.dialog_guadan_turn_room, null);
        idTvRight = (TextView) inflate.findViewById(R.id.id_tv_right);
        idTvClose = ((TextView) inflate.findViewById(R.id.id_tv_close));
        idTvRoomName = ((TextView) inflate.findViewById(R.id.id_tv_room_name));
        idTvRoomName.setText("房台：" + title);
        idTvRemark = ((TextView) inflate.findViewById(R.id.id_tv_remarks));
        idTvRemark.setText("备注：" + remark);
        //设置背景颜色，和背景的透明圆弧角度
        inflate.setBackgroundDrawable(
                CornerUtils.cornerDrawable(Color.parseColor("#f8f9fa"), dp2px(10)));

        return inflate;
    }

    @Override
    public void setUiBeforShow() {
        idTvRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initHttp();

            }
        });
        idTvClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

    private void initHttp() {
        HttpRequest.postUrl(Api.GUADAN_TURN_ROOM)
                .addParams("gid",gid)
                .addParams("group_id",group_id)
                .execute(new PostProcess.StringCallBack() {
                    @Override
                    public void onResponse(String json) {
                        boolean checkCode = Utils.checkCode(context, json);
                        if (checkCode){
                            simpleInterface.nothing();
                            dismiss();
                        }
                    }

                    @Override
                    public void onError(Exception e) {

                    }
                });
    }
}
